
#include "drawingtool.h"

RGBA  RGBA_DEFAULT(   0,   0,   0, 1);
RGBA  RGBA_RED(     1.0,   0,   0, 1);
RGBA  RGBA_GREEN(     0, 1.0,   0, 1);
RGBA  RGBA_BLUE(      0,   0, 1.0, 1);
RGBA  RGBA_WHITE(   1.0, 1.0, 1.0, 1);

////////////////////////////////////////////////////////////
// DTRECT implementation


DTRECT& DTRECT::inflate(double spacing) 
{
   X      -= spacing;
   Y      -= spacing;
   width  += spacing * 2;
   height += spacing * 2;
   
   return *this;
}

DTRECT& DTRECT::inflate(double x_diff, double y_diff, double w_diff, double h_diff)
{
   X      -= x_diff;
   Y      -= y_diff;
   width  += (x_diff + w_diff);
   height += (y_diff + h_diff);
   
   return *this; 
} 

DTRECT& DTRECT::moveTo(double x, double y) 
{
   X = x;
   Y = y;
   
   return *this;
}

DTRECT& DTRECT::moveTo(DTPOINT& pt)
{
   X = pt.X;
   Y = pt.Y;
   return *this;
}

DTRECT& DTRECT::centeredAt(DTPOINT& pt)
{
   return centeredAt(pt.X, pt.Y);
}

DTRECT& DTRECT::centeredAt(double cx, double cy)
{
   X = cx - 0.5 * width;
   Y = cy - 0.5 * height;
   
   return *this;
}   


///////////////////////////////////////////////////////////
// DrawingTool Class Implementation

void DrawingTool::map_coordination(double& posX, double& posY, int coord) 
{
   int mapping = (coord != 0) ? coord : coordination;
   int x_axis, y_axis, origin;
   
   if (coordination == mapping)
      return;
      
   if (coordination == TEXT_COORDINATION)
   {
      switch (mapping) 
      {
         case CHART_COORDINATION:
            posY = height - posY;
            break;
         case MATHEMATIC_COORDINATION:
            posX = posX + width / 2;
            posY = (height / 2) - posY; 
      	      break;
      }
   }
   else if (coordination == CHART_COORDINATION)
   {
      switch (mapping) 
      {
         case TEXT_COORDINATION:
            posY = height - posY;
            break;
         case MATHEMATIC_COORDINATION:
            posX += (width / 2);
            posY += (height / 2);
            break;
      }
   }
   else if (coordination == MATHEMATIC_COORDINATION)
   {
      switch (mapping) 
      {
         case TEXT_COORDINATION:
            break;
         case CHART_COORDINATION:
            break;
      }
   }

   return;
}

void DrawingTool::map_coordination(double& x, double& y, double& w, double& h, int coord)
{
   map_coordination(x,y, coord);
   
   switch (coordination)
   {
      case TEXT_COORDINATION:
         break;
      case CHART_COORDINATION:
      case MATHEMATIC_COORDINATION:
         y *= -1;
   	   break;
   }

   return;
}


